/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package eu.bopet.jocadv.core.constraints;

import eu.bopet.jocadv.core.Constraint;
import eu.bopet.jocadv.core.Differentiable;
import eu.bopet.jocadv.core.datum.Plane;
import eu.bopet.jocadv.core.datum.Point;
import java.io.Serializable;

/**
 * The class represents geometric constraint of point on plane
 *
 * @author bocskapeter
 */
public class PointOnPlane extends Constraint implements Serializable, Differentiable {

    /**
     * Default constructor
     *
     * @param name
     * @param point
     * @param plane
     */
    public PointOnPlane(String name, Point point, Plane plane) {
        super(name);
        this.addToElementList(point);
        this.addToElementList(plane);
    }

    /**
     * Gives the value of the equation at the given point<br>
     * Variables: point1: x1, y1, z1 ; plane1: a, b, c, d.<br>
     * Equation: a * x1 + b * y1 + c * z1 + d
     *
     * @param p - point
     * @return double value
     */
    @Override
    public double getVaue(double[] p) {
        return p[3] * p[0] + p[4] * p[1] + p[5] * p[2] + p[6];
    }

    /**
     * Gives the values of the partial derivative at the given point<br>
     * Variables: point1: x1, y1, z1 ; plane1: a, b, c, d.<br>
     * <p>Partial derivatives: <br><br>
     * point1: <br>
     * dx1: a <br>     
     * dy1: b <br>     
     * dz1: c <br><br>
     * plane1: <br>     
     * da: x1 <br>     
     * db: y1 <br>     
     * dc: z1 <br>     
     * dd: 0 <br></p>
     * 
     * @param p
     * @return 
     */
    @Override
    public double[][] getDerivatives(double[] p) {
        double[][] jacobi = new double[3][3];
        
        //dx1:
        jacobi[0][0] = p[3];
        //dy1:
        jacobi[0][1] = p[4];
        //dz1:
        jacobi[0][2] = p[5];

        //da:
        jacobi[1][0] = p[0];
        //db:
        jacobi[1][1] = p[1];
        //dc:
        jacobi[1][2] = p[2];
        
        return jacobi;
    }

}
